<html>

<head>

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta content="always" name="referrer">
    <meta name="theme-color" content="#ffffff">
</head>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.1/css/bootstrap.min.css" rel="stylesheet">
<title>重置用户绑定关系路径</title>

<body>
    <div class="container" style="padding: 20px;">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <button type="button" id="btn_parent_path" class="btn btn-info" onclick="parent_path()">重置绑定关系</button>
                <button type="button" id="btn_next_count" class="btn btn-success" onclick="next_count()">重置下级个数</button>
                <button type="button" id="btn_next_next_count" class="btn btn-primary"
                    onclick="next_next_count()">重置下下级个数</button>

            </div>
        </div>
        <div class="col-md-12 column">
            <div class="col-md-12 column" style="margin-top: 50px;">
                <div class="row clearfix" style="    border: 1px solid #9c9c9c; min-height: 600px;" id="result">


                </div>
            </div>

        </div>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.1/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        let count = 860;
        let danci = 100;
        let total = 86000;
        function parent_path() {
            $('#btn_parent_path').attr('disabled', true);
            $('#btn_parent_path').html('执行中');
            for (var i = 0; i < count; i++) {
                let sid = i * danci;
                let eid = (i + 1) * danci;
                $.ajax({
                    url: '/admin/user/add_path?sid=' + sid + '&eid=' + eid,
                    type: 'get',
                    async: false,
                    success: function (res) {
                        console.log('重置绑定关系路径：用户id' + sid + '到' + eid + '执行成功');
                        // $('#result').prepend('重置绑定关系路径：用户id' + sid + '到' + eid + '执行成功' + '<br/>');
                    }
                });
                sleep(1000);

            }

            $('#btn_parent_path').attr('disabled', false);
            $('#btn_parent_path').html('执行完成');

        }
        function next_count() {
            $('#btn_next_count').attr('disabled', true);
            $('#btn_next_count').html('执行中');
            // return;
            for (var i = 0; i < count; i++) {
                let sid = i * danci;
                let eid = (i + 1) * danci;
                $.ajax({
                    url: '/admin/user/nextCount?type=nextCount&sid=' + sid + '&eid=' + eid,
                    type: 'get',
                    async: false,
                    success: function (res) {
                        console.log('重置下级个数：用户id' + sid + '到' + eid + '执行成功 ')
                        // $('#result').prepend('重置下级个数：用户id' + sid + '到' + eid + '执行成功 <br/>');
                    }
                })
                sleep(1000);
            }

            $('#btn_next_count').attr('disabled', false);
            $('#btn_next_count').html('执行完成');


        }
        function next_next_count() {
            $('#btn_next_next_count').attr('disabled', true);
            $('#btn_next_next_count').html('执行中');
            for (var i = 0; i < count; i++) {
                let sid = i * danci;
                let eid = (i + 1) * danci;
                $.ajax({
                    url: '/admin/user/nextCount?type=next_next_count&sid=' + sid + '&eid=' + eid,
                    type: 'get',
                    async: false,
                    success: function (res) {
                        console.log('重置下级个数：用户id' + sid + '到' + eid + '执行成功');
                        //$('#result').prepend('重置下级个数：用户id' + sid + '到' + eid + '执行成功' + '<br/>');
                    }
                })
                sleep(1000);
            }
            $('#btn_next_next_count').attr('disabled', false);
            $('#btn_next_next_count').html('执行完成');


        }
        function sleep(n) { //n表示的毫秒数
            var start = new Date().getTime();
            while (true) if (new Date().getTime() - start > n) break;
        }  
    </script>
</body>

</html>